﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SWENAssignment.HuiYi
{
    public partial class updateUserAccDisplay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblLoginID.Text = (string)Session["loginID"];
            if (!Page.IsPostBack)
            {
                userAccount u = DBmanager.GetUserAccountByLoginID(lblLoginID.Text);
               
                lblLoginID.Text = u.LoginID;
                tbxPassword.Text = u.Password;
                tbxConfirmedPassword.Text = u.ConfirmedPassword;
                tbxContactNo.Text = u.ContNum.ToString();
                tbxAddress.Text = u.MailAdd;
                tbxEmail.Text = u.Email;

            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {

            userAccount updateUserAccount = new userAccount();
            updateUserAccount.LoginID = lblLoginID.Text;
            updateUserAccount.Password = tbxPassword.Text;
            updateUserAccount.ConfirmedPassword = tbxConfirmedPassword.Text;
            
            updateUserAccount.ContNum = Convert.ToInt32(tbxContactNo.Text);
            updateUserAccount.MailAdd = tbxAddress.Text;
            updateUserAccount.Email = tbxEmail.Text;



            if (DBmanager.UpdateUserAccount(updateUserAccount) == 1)
            {
                Session["loginID"] = updateUserAccount.LoginID;
                lblUpdatedSuccessfully.Text = "Account details updated!";
            }
            else
            {
                lblUpdatedSuccessfully.Text = "Account details not updated :(";
            }


        }
    }
}